home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / u_man / cat1 / perldebug.Z / perldebug
Encoding:
Text File  |  1998-10-28  |  75.0 KB  |  2,113 lines

  1.  
  2.  
  3.  
  4.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       perldebug - Perl debugging
  10.  
  11.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  12.       First    of all,    have you tried using the ----wwww switch?
  13.  
  14.      TTTThhhheeee PPPPeeeerrrrllll DDDDeeeebbbbuuuuggggggggeeeerrrr
  15.       "As soon as we started programming, we found to our surprise
  16.       that it wasn't as easy to get    programs right as we had
  17.       thought.  Debugging had to be    discovered.  I can remember
  18.       the exact instant when I realized that a large part of my
  19.       life from then on was    going to be spent in finding mistakes
  20.       in my    own programs."
  21.  
  22.         --_M_a_u_r_i_c_e _W_i_l_k_e_s, _1_9_4_9
  23.  
  24.       If you invoke    Perl with the ----dddd switch, your script runs
  25.       under    the Perl source    debugger.  This    works like an
  26.       interactive Perl environment,    prompting for debugger
  27.       commands that    let you    examine    source code, set breakpoints,
  28.       get stack backtraces,    change the values of variables,    etc.
  29.       This is so convenient    that you often fire up the debugger
  30.       all by itself    just to    test out Perl constructs interactively
  31.       to see what they do.    For example:
  32.  
  33.           perl -d -e 42
  34.  
  35.       In Perl, the debugger    is not a separate program as it
  36.       usually is in    the typical compiled environment.  Instead,
  37.       the ----dddd flag tells the    compiler to insert source information
  38.       into the parse trees it's about to hand off to the
  39.       interpreter.    That means your    code must first    compile
  40.       correctly for    the debugger to    work on    it.  Then when the
  41.       interpreter starts up, it preloads a Perl library file
  42.       containing the debugger itself.
  43.  
  44.       The program will halt    _r_i_g_h_t _b_e_f_o_r_e the first run-time
  45.       executable statement (but see    below regarding    compile-time
  46.       statements) and ask you to enter a debugger command.
  47.       Contrary to popular expectations, whenever the debugger
  48.       halts    and shows you a    line of    code, it always    displays the
  49.       line it's _a_b_o_u_t to execute, rather than the one it has just
  50.       executed.
  51.  
  52.       Any command not recognized by    the debugger is    directly
  53.       executed (eval'd) as Perl code in the    current    package.  (The
  54.       debugger uses    the DB package for its own state information.)
  55.  
  56.       Leading white    space before a command would cause the
  57.       debugger to think it's _N_O_T a debugger    command    but for    Perl,
  58.       so be    careful    not to do that.
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  71.  
  72.  
  73.  
  74.       DDDDeeeebbbbuuuuggggggggeeeerrrr CCCCoooommmmmmmmaaaannnnddddssss
  75.  
  76.       The debugger understands the following commands:
  77.  
  78.       h [command] Prints out a help    message.
  79.  
  80.               If you supply another debugger command as    an
  81.               argument to the h    command, it prints out the
  82.               description for just that    command.  The special
  83.               argument of h h produces a more compact help
  84.               listing, designed    to fit together    on one screen.
  85.  
  86.               If the output of the h command (or any command,
  87.               for that matter) scrolls past your screen,
  88.               either precede the command with a    leading    pipe
  89.               symbol so    it's run through your pager, as    in
  90.  
  91.               DB> |h
  92.  
  93.               You may change the pager which is    used via O
  94.               pager=...    command.
  95.  
  96.       p expr      Same as print {$DB::OUT} expr in the current
  97.               package.    In particular, because this is just
  98.               Perl's own pppprrrriiiinnnntttt function, this means that
  99.               nested data structures and objects are not
  100.               dumped, unlike with the x    command.
  101.  
  102.               The DB::OUT filehandle is    opened to /_d_e_v/_t_t_y,
  103.               regardless of where STDOUT may be    redirected to.
  104.  
  105.       x expr      Evaluates    its expression in list context and
  106.               dumps out    the result in a    pretty-printed
  107.               fashion.    Nested data structures are printed out
  108.               recursively, unlike the print function.
  109.  
  110.               The details of printout are governed by multiple
  111.               Options.
  112.  
  113.       V [pkg [vars]]
  114.               Display all (or some) variables in package
  115.               (defaulting to the main package) using a data
  116.               pretty-printer (hashes show their    keys and
  117.               values so    you see    what's what, control
  118.               characters are made printable, etc.).  Make sure
  119.               you don't    put the    type specifier (like $)    there,
  120.               just the symbol names, like this:
  121.  
  122.               V DB filename    line
  123.  
  124.               Use ~pattern and !pattern    for positive and
  125.               negative regexps.
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  137.  
  138.  
  139.  
  140.               Nested data structures are printed out in    a
  141.               legible fashion, unlike the print    function.
  142.  
  143.               The details of printout are governed by multiple
  144.               Options.
  145.  
  146.       X [vars]    Same as V    currentpackage [vars].
  147.  
  148.       T          Produce a    stack backtrace.  See below for
  149.               details on its output.
  150.  
  151.       s [expr]    Single step.  Executes until it reaches the
  152.               beginning    of another statement, descending into
  153.               subroutine calls.     If an expression is supplied
  154.               that includes function calls, it too will    be
  155.               single-stepped.
  156.  
  157.       n [expr]    Next.  Executes over subroutine calls, until it
  158.               reaches the beginning of the next    statement.  If
  159.               an expression is supplied    that includes function
  160.               calls, those functions will be executed with
  161.               stops before each    statement.
  162.  
  163.       <CR>          Repeat last n or s command.
  164.  
  165.       c [line|sub]
  166.               Continue,    optionally inserting a one-time-only
  167.               breakpoint at the    specified line or subroutine.
  168.  
  169.       l          List next    window of lines.
  170.  
  171.       l min+incr  List incr+1 lines    starting at min.
  172.  
  173.       l min-max   List lines min through max.  l - is synonymous
  174.               to -.
  175.  
  176.       l line      List a single line.
  177.  
  178.       l subname   List first window    of lines from subroutine.
  179.  
  180.       -          List previous window of lines.
  181.  
  182.       w [line]    List window (a few lines)    around the current
  183.               line.
  184.  
  185.       .          Return debugger pointer to the last-executed
  186.               line and print it    out.
  187.  
  188.       f filename  Switch to    viewing    a different file or eval
  189.               statement.  If filename is not a full filename
  190.               as found in values of %INC, it is    considered as
  191.               a    regexp.
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  203.  
  204.  
  205.  
  206.       /pattern/   Search forwards for pattern; final / is
  207.               optional.
  208.  
  209.       ?pattern?   Search backwards for pattern; final ? is
  210.               optional.
  211.  
  212.       L          List all breakpoints and actions.
  213.  
  214.       S [[!]pattern]
  215.               List subroutine names [not] matching pattern.
  216.  
  217.       t          Toggle trace mode    (see also AutoTrace Option).
  218.  
  219.       t expr      Trace through execution of expr.    For example:
  220.  
  221.                $ perl -de 42
  222.                Stack dump during die enabled outside of    evals.
  223.  
  224.                Loading DB routines from    perl5db.pl patch level 0.94
  225.                Emacs support available.
  226.  
  227.                Enter h or `h h'    for help.
  228.  
  229.                main::(-e:1):   0
  230.              DB<1> sub foo { 14 }
  231.  
  232.              DB<2> sub bar { 3 }
  233.  
  234.              DB<3> t print foo() * bar()
  235.                main::((eval 172):3):   print foo() + bar();
  236.                main::foo((eval 168):2):
  237.                main::bar((eval 170):2):
  238.                42
  239.  
  240.               or, with the Option frame=2 set,
  241.  
  242.              DB<4> O f=2
  243.                       frame = '2'
  244.              DB<5> t print foo() * bar()
  245.                3:      foo() * bar()
  246.                entering    main::foo
  247.             2:     sub foo { 14 };
  248.                exited main::foo
  249.                entering    main::bar
  250.             2:     sub bar { 3 };
  251.                exited main::bar
  252.                42
  253.  
  254.  
  255.       b [line] [condition]
  256.               Set a breakpoint.     If line is omitted, sets a
  257.               breakpoint on the    line that is about to be
  258.  
  259.  
  260.  
  261.      Page 4                        (printed 10/23/98)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  269.  
  270.  
  271.  
  272.               executed.     If a condition    is specified, it's
  273.               evaluated    each time the statement    is reached and
  274.               a    breakpoint is taken only if the    condition is
  275.               true.  Breakpoints may be    set on only lines that
  276.               begin an executable statement.  Conditions don't
  277.               use iiiiffff:
  278.  
  279.               b 237    $x > 30
  280.               b 237    ++$count237 < 11
  281.               b 33 /pattern/i
  282.  
  283.  
  284.       b subname [condition]
  285.               Set a breakpoint at the first line of the    named
  286.               subroutine.
  287.  
  288.       b postpone subname [condition]
  289.               Set breakpoint at    first line of subroutine after
  290.               it is compiled.
  291.  
  292.       b load filename
  293.               Set breakpoint at    the first executed line    of the
  294.               file.  Filename should be    a full name as found
  295.               in values    of %INC.
  296.  
  297.       b compile subname
  298.               Sets breakpoint at the first statement executed
  299.               after the    subroutine is compiled.
  300.  
  301.       d [line]    Delete a breakpoint at the specified line.  If
  302.               line is omitted, deletes the breakpoint on the
  303.               line that    is about to be executed.
  304.  
  305.       D          Delete all installed breakpoints.
  306.  
  307.       a [line] command
  308.               Set an action to be done before the line is
  309.               executed.     The sequence of steps taken by    the
  310.               debugger is
  311.  
  312.             1. check for a breakpoint at this line
  313.             2. print the line if necessary (tracing)
  314.             3. do any actions associated with that line
  315.             4. prompt user if at a breakpoint or in    single-step
  316.             5. evaluate line
  317.  
  318.               For example, this    will print out $foo every time
  319.               line 53 is passed:
  320.  
  321.               a 53 print "DB FOUND $foo\n"
  322.  
  323.  
  324.  
  325.  
  326.  
  327.      Page 5                        (printed 10/23/98)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  335.  
  336.  
  337.  
  338.       A          Delete all installed actions.
  339.  
  340.       W [expr]    Add a global watch-expression.
  341.  
  342.       W          Delete all watch-expressions.
  343.  
  344.       O [opt[=val]]    [op'val' [opt?]...
  345.               Set or query values of options.  val defaults to
  346.               1.  opt can be abbreviated.  Several options can
  347.               be listed.
  348.  
  349.       recallCommand, ShellBang
  350.                   The characters used to recall
  351.                   command or spawn shell.  By default,
  352.                   these    are both set to    !.
  353.  
  354.       pager              Program to use for output of pager-
  355.                   piped    commands (those    beginning with
  356.                   a | character.)  By default,
  357.                   $ENV{PAGER} will be used.
  358.  
  359.       tkRunning          Run Tk while prompting (with
  360.                   ReadLine).
  361.  
  362.       signalLevel, warnLevel, dieLevel
  363.                   Level    of verbosity.  By default the
  364.                   debugger is in a sane    verbose    mode,
  365.                   thus it will print backtraces    on all
  366.                   the warnings and die-messages    which
  367.                   are going to be printed out, and
  368.                   will print a message when
  369.                   interesting uncaught signals arrive.
  370.  
  371.                   To disable this behaviour, set these
  372.                   values to 0.    If dieLevel is 2, then
  373.                   the messages which will be caught by
  374.                   surrounding eval are also printed.
  375.  
  376.       AutoTrace          Trace    mode (similar to t command,
  377.                   but can be put into PERLDB_OPTS).
  378.  
  379.       LineInfo          File or pipe to print    line number
  380.                   info to.  If it is a pipe (say,
  381.                   |visual_perl_db), then a short,
  382.                   "emacs like" message is used.
  383.  
  384.       inhibit_exit          If 0,    allows _s_t_e_p_p_i_n_g    _o_f_f the    end of
  385.                   the script.
  386.  
  387.       PrintRet          affects printing of return value
  388.                   after    r command.
  389.  
  390.  
  391.  
  392.  
  393.      Page 6                        (printed 10/23/98)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  401.  
  402.  
  403.  
  404.       ornaments          affects screen appearance of the
  405.                   command line (see the    _T_e_r_m::_R_e_a_d_L_i_n_e
  406.                   manpage).
  407.  
  408.       frame              affects printing messages on entry
  409.                   and exit from    subroutines.  If frame
  410.                   & 2 is false,    messages are printed
  411.                   on entry only. (Printing on exit may
  412.                   be useful if _i_n_t_e_r(di)spersed    with
  413.                   other    messages.)
  414.  
  415.                   If frame & 4,    arguments to functions
  416.                   are printed as well as the context
  417.                   and caller info.  If frame & 8,
  418.                   overloaded stringify and tied    FETCH
  419.                   are enabled on the printed
  420.                   arguments. If    frame &    16, the    return
  421.                   value    from the subroutine is printed
  422.                   as well.
  423.  
  424.                   The length at    which the argument
  425.                   list is truncated is governed    by the
  426.                   next option:
  427.  
  428.       maxTraceLen          length at which the argument list is
  429.                   truncated when frame option's    bit 4
  430.                   is set.
  431.  
  432.                   The following    options    affect what
  433.                   happens with V, X, and x commands:
  434.  
  435.       arrayDepth, hashDepth      Print    only first N elements ('' for
  436.                   all).
  437.  
  438.       compactDump, veryCompact
  439.                   Change style of array    and hash dump.
  440.                   If compactDump, short    array may be
  441.                   printed on one line.
  442.  
  443.       globPrint          Whether to print contents of globs.
  444.  
  445.       DumpDBFiles          Dump arrays holding debugged files.
  446.  
  447.       DumpPackages          Dump symbol tables of    packages.
  448.  
  449.       DumpReused          Dump contents    of "reused" addresses.
  450.  
  451.       quote, HighBit, undefPrint
  452.                   Change style of string dump.
  453.                   Default value    of quote is auto, one
  454.                   can enable either double-quotish
  455.                   dump,    or single-quotish by setting
  456.  
  457.  
  458.  
  459.      Page 7                        (printed 10/23/98)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  467.  
  468.  
  469.  
  470.                   it to    " or '.     By default,
  471.                   characters with high bit set are
  472.                   printed _a_s _i_s.
  473.  
  474.       UsageOnly          _v_e_r_y rudimentally per-package    memory
  475.                   usage    dump.  Calculates total    size
  476.                   of strings in    variables in the
  477.                   package.
  478.  
  479.                   During startup options are
  480.                   initialized from $ENV{PERLDB_OPTS}.
  481.                   You can put additional
  482.                   initialization options TTY, noTTY,
  483.                   ReadLine, and    NonStop    there.
  484.  
  485.                   Example rc file:
  486.  
  487.                     &parse_options("NonStop=1 LineInfo=db.out AutoTrace");
  488.  
  489.                   The script will run without human
  490.                   intervention,    putting    trace
  491.                   information into the file _d_b._o_u_t.
  492.                   (If you interrupt it,    you would
  493.                   better reset LineInfo    to something
  494.                   "interactive"!)
  495.  
  496.       TTY              The TTY to use for debugging I/O.
  497.  
  498.       noTTY              If set, goes in NonStop mode,    and
  499.                   would    not connect to a TTY.  If
  500.                   interrupt (or    if control goes    to
  501.                   debugger via explicit    setting    of
  502.                   $DB::signal or $DB::single from the
  503.                   Perl script),    connects to a TTY
  504.                   specified by the TTY option at
  505.                   startup, or to a TTY found at
  506.                   runtime using    Term::Rendezvous
  507.                   module of your choice.
  508.  
  509.                   This module should implement a
  510.                   method new which returns an object
  511.                   with two methods: IN and OUT,
  512.                   returning two    filehandles to use for
  513.                   debugging input and output
  514.                   correspondingly.  Method new may
  515.                   inspect an argument which is a value
  516.                   of $ENV{PERLDB_NOTTY}    at startup, or
  517.                   is "/tmp/perldbtty$$"    otherwise.
  518.  
  519.       ReadLine          If false, readline support in
  520.                   debugger is disabled,    so you can
  521.                   debug    ReadLine applications.
  522.  
  523.  
  524.  
  525.      Page 8                        (printed 10/23/98)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  533.  
  534.  
  535.  
  536.       NonStop          If set, debugger goes    into
  537.                   noninteractive mode until
  538.                   interrupted, or programmatically by
  539.                   setting $DB::signal or $DB::single.
  540.  
  541.                   Here's an example of using the
  542.                   $ENV{PERLDB_OPTS} variable:
  543.  
  544.                     $ PERLDB_OPTS="N f=2" perl -d myprogram
  545.  
  546.                   will run the script myprogram
  547.                   without human    intervention, printing
  548.                   out the call tree with entry and
  549.                   exit points.    Note that N f=2    is
  550.                   equivalent to    NonStop=1 frame=2.
  551.                   Note also that at the    moment when
  552.                   this documentation was written all
  553.                   the options to the debugger could be
  554.                   uniquely abbreviated by the first
  555.                   letter (with exception of Dump*
  556.                   options).
  557.  
  558.                   Other    examples may include
  559.  
  560.                     $ PERLDB_OPTS="N f A L=listing" perl -d myprogram
  561.  
  562.                   - runs script    noninteractively,
  563.                   printing info    on each    entry into a
  564.                   subroutine and each executed line
  565.                   into the file    _l_i_s_t_i_n_g. (If you
  566.                   interrupt it,    you would better reset
  567.                   LineInfo to something
  568.                   "interactive"!)
  569.  
  570.                     $ env "PERLDB_OPTS=R=0 TTY=/dev/ttyc" perl -d myprogram
  571.  
  572.                   may be useful    for debugging a
  573.                   program which    uses Term::ReadLine
  574.                   itself.  Do not forget detach    shell
  575.                   from the TTY in the window which
  576.                   corresponds to /_d_e_v/_t_t_y_c, say, by
  577.                   issuing a command like
  578.  
  579.                     $ sleep 1000000
  580.  
  581.                   See the section on _D_e_b_u_g_g_e_r
  582.                   _I_n_t_e_r_n_a_l_s below for more details.
  583.  
  584.       < [ command ]
  585.               Set an action (Perl command) to happen before
  586.               every debugger prompt.  A    multi-line command may
  587.               be entered by backslashing the newlines.    If
  588.  
  589.  
  590.  
  591.      Page 9                        (printed 10/23/98)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  599.  
  600.  
  601.  
  602.               command is missing, resets the list of actions.
  603.  
  604.       << command  Add an action (Perl command) to happen before
  605.               every debugger prompt.  A    multi-line command may
  606.               be entered by backslashing the newlines.
  607.  
  608.       > command   Set an action (Perl command) to happen after the
  609.               prompt when you've just given a command to
  610.               return to    executing the script.  A multi-line
  611.               command may be entered by    backslashing the
  612.               newlines.     If command is missing,    resets the
  613.               list of actions.
  614.  
  615.       >> command  Adds an action (Perl command) to happen after
  616.               the prompt when you've just given    a command to
  617.               return to    executing the script.  A multi-line
  618.               command may be entered by    backslashing the
  619.               newlines.
  620.  
  621.       { [ command ]
  622.               Set an action (debugger command) to happen
  623.               before every debugger prompt.  A multi-line
  624.               command may be entered by    backslashing the
  625.               newlines.     If command is missing,    resets the
  626.               list of actions.
  627.  
  628.       {{ command  Add an action (debugger command) to happen
  629.               before every debugger prompt.  A multi-line
  630.               command may be entered by    backslashing the
  631.               newlines.
  632.  
  633.       ! number    Redo a previous command (default previous
  634.               command).
  635.  
  636.       ! -number   Redo number'th-to-last command.
  637.  
  638.       ! pattern   Redo last    command    that started with pattern.
  639.               See O recallCommand, too.
  640.  
  641.       !! cmd      Run cmd in a subprocess (reads from DB::IN,
  642.               writes to    DB::OUT) See O shellBang too.
  643.  
  644.       H -number   Display last n commands.    Only commands longer
  645.               than one character are listed.  If number    is
  646.               omitted, lists them all.
  647.  
  648.       q or ^D     Quit.  ("quit" doesn't work for this.)  This is
  649.               the only supported way to    exit the debugger,
  650.               though typing exit twice may do it too.
  651.  
  652.               Set an Option inhibit_exit to 0 if you want to
  653.               be able to _s_t_e_p _o_f_f the end the script.  You may
  654.  
  655.  
  656.  
  657.      Page 10                        (printed 10/23/98)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  665.  
  666.  
  667.  
  668.               also need    to set $finished to 0 at some moment
  669.               if you want to step through global destruction.
  670.  
  671.       R          Restart the debugger by eeeexxxxeeeeccccing a    new session.
  672.               It tries to maintain your    history    across this,
  673.               but internal settings and    command    line options
  674.               may be lost.
  675.  
  676.               Currently    the following setting are preserved:
  677.               history, breakpoints, actions, debugger Options,
  678.               and the following    command    line options: ----wwww, ----IIII,
  679.               and ----eeee.
  680.  
  681.       |dbcmd      Run debugger command, piping DB::OUT to current
  682.               pager.
  683.  
  684.       ||dbcmd     Same as |dbcmd but DB::OUT is temporarily
  685.               sssseeeelllleeeecccctttted as well.     Often used with commands that
  686.               would otherwise produce long output, such    as
  687.  
  688.               |V main
  689.  
  690.  
  691.       = [alias value]
  692.               Define a command alias, like
  693.  
  694.               = quit q
  695.  
  696.               or list current aliases.
  697.  
  698.       command     Execute command as a Perl    statement.  A missing
  699.               semicolon    will be    supplied.
  700.  
  701.       m expr      The expression is    evaluated, and the methods
  702.               which may    be applied to the result are listed.
  703.  
  704.       m package   The methods which    may be applied to objects in
  705.               the package are listed.
  706.  
  707.       DDDDeeeebbbbuuuuggggggggeeeerrrr iiiinnnnppppuuuutttt////oooouuuuttttppppuuuutttt
  708.  
  709.       Prompt  The debugger prompt is something like
  710.  
  711.               DB<8>
  712.  
  713.           or even
  714.  
  715.               DB<<17>>
  716.  
  717.           where    that number is the command number, which you'd
  718.           use to access    with the builtin ccccsssshhhh-like history
  719.           mechanism, e.g., !17 would repeat command number 17.
  720.  
  721.  
  722.  
  723.      Page 11                        (printed 10/23/98)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  731.  
  732.  
  733.  
  734.           The number of    angle brackets indicates the depth of
  735.           the debugger.     You could get more than one set of
  736.           brackets, for    example, if you'd already at a
  737.           breakpoint and then printed out the result of    a
  738.           function call    that itself also has a breakpoint, or
  739.           you step into    an expression via s/n/t    expression
  740.           command.
  741.  
  742.       Multiline commands
  743.           If you want to enter a multi-line command, such as a
  744.           subroutine definition    with several statements, or a
  745.           format, you may escape the newline that would
  746.           normally end the debugger command with a backslash.
  747.           Here's an example:
  748.  
  749.             DB<1> for (1..4) {       \
  750.             cont:      print    "ok\n";      \
  751.             cont: }
  752.             ok
  753.             ok
  754.             ok
  755.             ok
  756.  
  757.           Note that this business of escaping a    newline    is
  758.           specific to interactive commands typed into the
  759.           debugger.
  760.  
  761.       Stack    backtrace
  762.           Here's an example of what a stack backtrace via T
  763.           command might    look like:
  764.  
  765.               $    = main::infested called    from file `Ambulation.pm' line 10
  766.               @    = Ambulation::legs(1, 2, 3, 4) called from file    `camel_flea' line 7
  767.               $    = main::pests('bactrian', 4) called from file `camel_flea' line    4
  768.  
  769.           The left-hand    character up there tells whether the
  770.           function was called in a scalar or list context (we
  771.           bet you can tell which is which).  What that says is
  772.           that you were    in the function    main::infested when
  773.           you ran the stack dump, and that it was called in a
  774.           scalar context from line 10 of the file
  775.           _A_m_b_u_l_a_t_i_o_n._p_m, but without any arguments at all,
  776.           meaning it was called    as &infested.  The next    stack
  777.           frame    shows that the function    Ambulation::legs was
  778.           called in a list context from    the _c_a_m_e_l__f_l_e_a file
  779.           with four arguments.    The last stack frame shows
  780.           that main::pests was called in a scalar context,
  781.           also from _c_a_m_e_l__f_l_e_a,    but from line 4.
  782.  
  783.           Note that if you execute T command from inside an
  784.           active use statement,    the backtrace will contain
  785.           both require frame and an eval) frame.
  786.  
  787.  
  788.  
  789.      Page 12                        (printed 10/23/98)
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  797.  
  798.  
  799.  
  800.       Listing Listing given    via different flavors of l command
  801.           looks    like this:
  802.  
  803.               DB<<13>> l
  804.             101:        @i{@i} = ();
  805.             102:b        @isa{@i,$pack} = ()
  806.             103                if(exists $i{$prevpack} || exists $isa{$pack});
  807.             104            }
  808.             105
  809.             106            next
  810.             107==>        if(exists $isa{$pack});
  811.             108
  812.             109:a        if ($extra-- > 0) {
  813.             110:        %isa = ($pack,1);
  814.  
  815.           Note that the    breakable lines    are marked with    :,
  816.           lines    with breakpoints are marked by b, with actions
  817.           by a,    and the    next executed line is marked by    ==>.
  818.  
  819.       Frame    listing
  820.           When frame option is set, debugger would print
  821.           entered (and optionally exited) subroutines in
  822.           different styles.
  823.  
  824.           What follows is the start of the listing of
  825.  
  826.             env    "PERLDB_OPTS=f=n N" perl -d -V
  827.  
  828.           for different    values of n:
  829.  
  830.       1
  831.  
  832.             entering main::BEGIN
  833.              entering Config::BEGIN
  834.               Package lib/Exporter.pm.
  835.               Package lib/Carp.pm.
  836.              Package lib/Config.pm.
  837.              entering Config::TIEHASH
  838.              entering Exporter::import
  839.               entering Exporter::export
  840.             entering Config::myconfig
  841.              entering Config::FETCH
  842.              entering Config::FETCH
  843.              entering Config::FETCH
  844.              entering Config::FETCH
  845.  
  846.  
  847.       2
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.      Page 13                        (printed 10/23/98)
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  863.  
  864.  
  865.  
  866.             entering main::BEGIN
  867.              entering Config::BEGIN
  868.               Package lib/Exporter.pm.
  869.               Package lib/Carp.pm.
  870.              exited    Config::BEGIN
  871.              Package lib/Config.pm.
  872.              entering Config::TIEHASH
  873.              exited    Config::TIEHASH
  874.              entering Exporter::import
  875.               entering Exporter::export
  876.               exited Exporter::export
  877.              exited    Exporter::import
  878.             exited main::BEGIN
  879.             entering Config::myconfig
  880.              entering Config::FETCH
  881.              exited    Config::FETCH
  882.              entering Config::FETCH
  883.              exited    Config::FETCH
  884.              entering Config::FETCH
  885.  
  886.  
  887.       4
  888.  
  889.             in  $=main::BEGIN() from /dev/nul:0
  890.              in  $=Config::BEGIN() from lib/Config.pm:2
  891.               Package lib/Exporter.pm.
  892.               Package lib/Carp.pm.
  893.              Package lib/Config.pm.
  894.              in  $=Config::TIEHASH('Config') from lib/Config.pm:644
  895.              in  $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/nul:0
  896.               in  $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from li
  897.             in  @=Config::myconfig() from /dev/nul:0
  898.              in  $=Config::FETCH(ref(Config), 'package') from lib/Config.pm:574
  899.              in  $=Config::FETCH(ref(Config), 'baserev') from lib/Config.pm:574
  900.              in  $=Config::FETCH(ref(Config), 'PATCHLEVEL')    from lib/Config.pm:574
  901.              in  $=Config::FETCH(ref(Config), 'SUBVERSION')    from lib/Config.pm:574
  902.              in  $=Config::FETCH(ref(Config), 'osname') from lib/Config.pm:574
  903.              in  $=Config::FETCH(ref(Config), 'osvers') from lib/Config.pm:574
  904.  
  905.  
  906.       6
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.      Page 14                        (printed 10/23/98)
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  929.  
  930.  
  931.  
  932.             in  $=main::BEGIN() from /dev/nul:0
  933.              in  $=Config::BEGIN() from lib/Config.pm:2
  934.               Package lib/Exporter.pm.
  935.               Package lib/Carp.pm.
  936.              out $=Config::BEGIN() from lib/Config.pm:0
  937.              Package lib/Config.pm.
  938.              in  $=Config::TIEHASH('Config') from lib/Config.pm:644
  939.              out $=Config::TIEHASH('Config') from lib/Config.pm:644
  940.              in  $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/nul:0
  941.               in  $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/
  942.               out $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/
  943.              out $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/nul:0
  944.             out $=main::BEGIN() from /dev/nul:0
  945.             in  @=Config::myconfig() from /dev/nul:0
  946.              in  $=Config::FETCH(ref(Config), 'package') from lib/Config.pm:574
  947.              out $=Config::FETCH(ref(Config), 'package') from lib/Config.pm:574
  948.              in  $=Config::FETCH(ref(Config), 'baserev') from lib/Config.pm:574
  949.              out $=Config::FETCH(ref(Config), 'baserev') from lib/Config.pm:574
  950.              in  $=Config::FETCH(ref(Config), 'PATCHLEVEL')    from lib/Config.pm:574
  951.              out $=Config::FETCH(ref(Config), 'PATCHLEVEL')    from lib/Config.pm:574
  952.              in  $=Config::FETCH(ref(Config), 'SUBVERSION')    from lib/Config.pm:574
  953.  
  954.  
  955.       14
  956.  
  957.             in  $=main::BEGIN() from /dev/nul:0
  958.              in  $=Config::BEGIN() from lib/Config.pm:2
  959.               Package lib/Exporter.pm.
  960.               Package lib/Carp.pm.
  961.              out $=Config::BEGIN() from lib/Config.pm:0
  962.              Package lib/Config.pm.
  963.              in  $=Config::TIEHASH('Config') from lib/Config.pm:644
  964.              out $=Config::TIEHASH('Config') from lib/Config.pm:644
  965.              in  $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/nul:0
  966.               in  $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/E
  967.               out $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/E
  968.              out $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/nul:0
  969.             out $=main::BEGIN() from /dev/nul:0
  970.             in  @=Config::myconfig() from /dev/nul:0
  971.              in  $=Config::FETCH('Config=HASH(0x1aa444)', 'package') from lib/Config.pm:574
  972.              out $=Config::FETCH('Config=HASH(0x1aa444)', 'package') from lib/Config.pm:574
  973.              in  $=Config::FETCH('Config=HASH(0x1aa444)', 'baserev') from lib/Config.pm:574
  974.              out $=Config::FETCH('Config=HASH(0x1aa444)', 'baserev') from lib/Config.pm:574
  975.  
  976.  
  977.       30
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.      Page 15                        (printed 10/23/98)
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  995.  
  996.  
  997.  
  998.             in  $=CODE(0x15eca4)() from /dev/null:0
  999.              in  $=CODE(0x182528)()    from lib/Config.pm:2
  1000.               Package lib/Exporter.pm.
  1001.              out $=CODE(0x182528)()    from lib/Config.pm:0
  1002.              scalar    context    return from CODE(0x182528): undef
  1003.              Package lib/Config.pm.
  1004.              in  $=Config::TIEHASH('Config') from lib/Config.pm:628
  1005.              out $=Config::TIEHASH('Config') from lib/Config.pm:628
  1006.              scalar    context    return from Config::TIEHASH:   empty hash
  1007.              in  $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
  1008.               in  $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/Exporter.pm:171
  1009.               out $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/Exporter.pm:171
  1010.               scalar context return    from Exporter::export: ''
  1011.              out $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
  1012.              scalar    context    return from Exporter::import: ''
  1013.  
  1014.  
  1015.               In all the cases indentation of lines shows the
  1016.               call tree, if bit    2 of frame is set, then    a line
  1017.               is printed on exit from a    subroutine as well, if
  1018.               bit 4 is set, then the arguments are printed as
  1019.               well as the caller info, if bit 8    is set,    the
  1020.               arguments    are printed even if they are tied or
  1021.               references, if bit 16 is set, the    return value
  1022.               is printed as well.
  1023.  
  1024.               When a package is    compiled, a line like this
  1025.  
  1026.               Package lib/Carp.pm.
  1027.  
  1028.               is printed with proper indentation.
  1029.  
  1030.       DDDDeeeebbbbuuuuggggggggiiiinnnngggg ccccoooommmmppppiiiilllleeee----ttttiiiimmmmeeee ssssttttaaaatttteeeemmmmeeeennnnttttssss
  1031.  
  1032.       If you have any compile-time executable statements (code
  1033.       within a BEGIN block or a use    statement), these will NOT be
  1034.       stopped by debugger, although    requires will (and compile-
  1035.       time statements can be traced    with AutoTrace option set in
  1036.       PERLDB_OPTS).     From your own Perl code, however, you can
  1037.       transfer control back    to the debugger    using the following
  1038.       statement, which is harmless if the debugger is not running:
  1039.  
  1040.           $DB::single = 1;
  1041.  
  1042.       If you set $DB::single to the    value 2, it's equivalent to
  1043.       having just typed the    n command, whereas a value of 1    means
  1044.       the s    command.  The $DB::trace  variable should be set to 1
  1045.       to simulate having typed the t command.
  1046.  
  1047.       Another way to debug compile-time code is to start debugger,
  1048.       set a    breakpoint on _l_o_a_d of some module thusly
  1049.  
  1050.  
  1051.  
  1052.  
  1053.      Page 16                        (printed 10/23/98)
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1061.  
  1062.  
  1063.  
  1064.           DB<7> b load f:/perllib/lib/Carp.pm
  1065.         Will stop on load of `f:/perllib/lib/Carp.pm'.
  1066.  
  1067.       and restart debugger by R command (if    possible).  One    can
  1068.       use b    compile    subname    for the    same purpose.
  1069.  
  1070.       DDDDeeeebbbbuuuuggggggggeeeerrrr CCCCuuuussssttttoooommmmiiiizzzzaaaattttiiiioooonnnn
  1071.  
  1072.       Most probably    you do not want    to modify the debugger,    it
  1073.       contains enough hooks    to satisfy most    needs.    You may    change
  1074.       the behaviour    of debugger from the debugger itself, using
  1075.       Options, from    the command line via PERLDB_OPTS environment
  1076.       variable, and    from _c_u_s_t_o_m_i_z_a_t_i_o_n _f_i_l_e_s.
  1077.  
  1078.       You can do some customization    by setting up a    ._p_e_r_l_d_b    file
  1079.       which    contains initialization    code.  For instance, you could
  1080.       make aliases like these (the last one    is one people expect
  1081.       to be    there):
  1082.  
  1083.           $DB::alias{'len'}     = 's/^len(.*)/p length($1)/';
  1084.           $DB::alias{'stop'} = 's/^stop (at|in)/b/';
  1085.           $DB::alias{'ps'}     = 's/^ps\b/p scalar /';
  1086.           $DB::alias{'quit'} = 's/^quit(\s*)/exit\$/';
  1087.  
  1088.       One changes options from ._p_e_r_l_d_b file    via calls like this
  1089.       one;
  1090.  
  1091.           parse_options("NonStop=1 LineInfo=db.out AutoTrace=1 frame=2");
  1092.  
  1093.       (the code is executed    in the package DB).  Note that ._p_e_r_l_d_b
  1094.       is processed before processing PERLDB_OPTS.  If ._p_e_r_l_d_b
  1095.       defines the subroutine afterinit, it is called after all the
  1096.       debugger initialization ends.     ._p_e_r_l_d_b may be    contained in
  1097.       the current directory, or in the LOGDIR/HOME directory.
  1098.  
  1099.       If you want to modify    the debugger, copy _p_e_r_l_5_d_b._p_l from the
  1100.       Perl library to another name and modify it as    necessary.
  1101.       You'll also want to set your PERL5DB environment variable to
  1102.       say something    like this:
  1103.  
  1104.           BEGIN { require "myperl5db.pl" }
  1105.  
  1106.       As the last resort, one can use PERL5DB to customize
  1107.       debugger by directly setting internal    variables or calling
  1108.       debugger functions.
  1109.  
  1110.       RRRReeeeaaaaddddlllliiiinnnneeee SSSSuuuuppppppppoooorrrrtttt
  1111.  
  1112.       As shipped, the only command line history supplied is    a
  1113.       simplistic one that checks for leading exclamation points.
  1114.       However, if you install the Term::ReadKey and    Term::ReadLine
  1115.       modules from CPAN, you will have full    editing    capabilities
  1116.  
  1117.  
  1118.  
  1119.      Page 17                        (printed 10/23/98)
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1127.  
  1128.  
  1129.  
  1130.       much like GNU    _r_e_a_d_l_i_n_e(3) provides.  Look for    these in the
  1131.       _m_o_d_u_l_e_s/_b_y-_m_o_d_u_l_e/_T_e_r_m directory on CPAN.
  1132.  
  1133.       A rudimentary    command    line completion    is also    available.
  1134.       Unfortunately, the names of lexical variables    are not
  1135.       available for    completion.
  1136.  
  1137.       EEEEddddiiiittttoooorrrr SSSSuuuuppppppppoooorrrrtttt ffffoooorrrr DDDDeeeebbbbuuuuggggggggiiiinnnngggg
  1138.  
  1139.       If you have GNU eeeemmmmaaaaccccssss    installed on your system, it can
  1140.       interact with    the Perl debugger to provide an    integrated
  1141.       software development environment reminiscent of its
  1142.       interactions with C debuggers.
  1143.  
  1144.       Perl is also delivered with a    start file for making eeeemmmmaaaaccccssss
  1145.       act like a syntax-directed editor that understands (some of)
  1146.       Perl's syntax.  Look in the _e_m_a_c_s directory of the Perl
  1147.       source distribution.
  1148.  
  1149.       (Historically, a similar setup for interacting with vvvviiii and
  1150.       the X11 window system    had also been available, but at    the
  1151.       time of this writing,    no debugger support for    vvvviiii currently
  1152.       exists.)
  1153.  
  1154.       TTTThhhheeee PPPPeeeerrrrllll PPPPrrrrooooffffiiiilllleeeerrrr
  1155.  
  1156.       If you wish to supply    an alternative debugger    for Perl to
  1157.       run, just invoke your    script with a colon and    a package
  1158.       argument given to the    ----dddd flag.  One of the most popular
  1159.       alternative debuggers    for Perl is DDDDPPPPrrrrooooffff, the Perl profiler.
  1160.       As of    this writing, DDDDPPPPrrrrooooffff is not included with the standard
  1161.       Perl distribution, but it is expected    to be included soon,
  1162.       for certain values of    "soon".
  1163.  
  1164.       Meanwhile, you can fetch the Devel::Dprof module from    CPAN.
  1165.       Assuming it's    properly installed on your system, to profile
  1166.       your Perl program in the file    _m_y_c_o_d_e._p_l, just    type:
  1167.  
  1168.           perl -d:DProf mycode.pl
  1169.  
  1170.       When the script terminates the profiler will dump the
  1171.       profile information to a file    called _t_m_o_n._o_u_t.  A tool like
  1172.       ddddpppprrrrooooffffpppppppp (also    supplied with the Devel::DProf package)    can be
  1173.       used to interpret the    information which is in    that profile.
  1174.  
  1175.       DDDDeeeebbbbuuuuggggggggeeeerrrr ssssuuuuppppppppoooorrrrtttt iiiinnnn ppppeeeerrrrllll
  1176.  
  1177.       When you call    the ccccaaaalllllllleeeerrrr function (see the caller entry in
  1178.       the _p_e_r_l_f_u_n_c manpage)    from the package DB, Perl sets the
  1179.       array    @DB::args to contain the arguments the corresponding
  1180.       stack    frame was called with.
  1181.  
  1182.  
  1183.  
  1184.  
  1185.      Page 18                        (printed 10/23/98)
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1193.  
  1194.  
  1195.  
  1196.       If perl is run with ----dddd option, the following additional
  1197.       features are enabled (cf. the    section    on $^_P in the _p_e_r_l_v_a_r
  1198.       manpage):
  1199.  
  1200.       +o    Perl inserts the    contents of $ENV{PERL5DB} (or BEGIN
  1201.            {require    'perl5db.pl'} if not present) before the first
  1202.            line of the application.
  1203.  
  1204.       +o    The array @{"_<$filename"} is the line-by-line contents
  1205.            of $filename for    all the    compiled files.     Same for
  1206.            evaled strings which contain subroutines, or which are
  1207.            currently executed.  The    $filename for evaled strings
  1208.            looks like (eval    34).
  1209.  
  1210.       +o    The hash    %{"_<$filename"} contains breakpoints and
  1211.            action (it is keyed by line number), and    individual
  1212.            entries are settable (as    opposed    to the whole hash).
  1213.            Only true/false is important to Perl, though the    values
  1214.            used by _p_e_r_l_5_d_b._p_l have the form
  1215.            "$break_condition\0$action".  Values are    magical    in
  1216.            numeric context:     they are zeros    if the line is not
  1217.            breakable.
  1218.  
  1219.            Same for    evaluated strings which    contain    subroutines,
  1220.            or which    are currently executed.     The $filename for
  1221.            evaled strings looks like (eval 34).
  1222.  
  1223.       +o    The scalar ${"_<$filename"} contains "_<$filename".
  1224.            Same for    evaluated strings which    contain    subroutines,
  1225.            or which    are currently executed.     The $filename for
  1226.            evaled strings looks like (eval 34).
  1227.  
  1228.       +o    After each required file    is compiled, but before    it is
  1229.            executed, DB::postponed(*{"_<$filename"}) is called (if
  1230.            subroutine DB::postponed    exists).  Here the $filename
  1231.            is the expanded name of the required file (as found in
  1232.            values of %INC).
  1233.  
  1234.       +o    After each subroutine subname is    compiled existence of
  1235.            $DB::postponed{subname} is checked.  If this key
  1236.            exists, DB::postponed(subname) is called    (if subroutine
  1237.            DB::postponed exists).
  1238.  
  1239.       +o    A hash %DB::sub is maintained, with keys    being
  1240.            subroutine names, values    having the form
  1241.            filename:startline-endline.  filename has the form
  1242.            (eval 31) for subroutines defined inside    evals.
  1243.  
  1244.       +o    When execution of the application reaches a place that
  1245.            can have    a breakpoint, a    call to    DB::DB() is performed
  1246.            if any one of variables $DB::trace, $DB::single,    or
  1247.            $DB::signal is true. (Note that these variables are not
  1248.  
  1249.  
  1250.  
  1251.      Page 19                        (printed 10/23/98)
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1259.  
  1260.  
  1261.  
  1262.            localizable.) This feature is disabled when the control
  1263.            is inside DB::DB() or functions called from it (unless
  1264.            $^D & (1<<30)).
  1265.  
  1266.       +o    When execution of the application reaches a subroutine
  1267.            call, a call to &DB::sub(_a_r_g_s) is performed instead,
  1268.            with $DB::sub being the name of the called subroutine.
  1269.            (Unless the subroutine is compiled in the package DB.)
  1270.  
  1271.       Note that if &DB::sub    needs some external data to be setup
  1272.       for it to work, no subroutine    call is    possible until this is
  1273.       done.     For the standard debugger $DB::deep (how many levels
  1274.       of recursion deep into the debugger you can go before    a
  1275.       mandatory break) gives an example of such a dependency.
  1276.  
  1277.       The minimal working debugger consists    of one line
  1278.  
  1279.         sub    DB::DB {}
  1280.  
  1281.       which    is quite handy as contents of PERL5DB environment
  1282.       variable:
  1283.  
  1284.         env    "PERL5DB=sub DB::DB {}"    perl -d    your-script
  1285.  
  1286.       Another (a little bit    more useful) minimal debugger can be
  1287.       created with the only    line being
  1288.  
  1289.         sub    DB::DB {print ++$i; scalar <STDIN>}
  1290.  
  1291.       This debugger    would print the    sequential number of
  1292.       encountered statement, and would wait    for your CR to
  1293.       continue.
  1294.  
  1295.       The following    debugger is quite functional:
  1296.  
  1297.         {
  1298.           package DB;
  1299.           sub DB  {}
  1300.           sub sub {print ++$i, " $sub\n"; &$sub}
  1301.         }
  1302.  
  1303.       It prints the    sequential number of subroutine    call and the
  1304.       name of the called subroutine.  Note that &DB::sub should be
  1305.       compiled into    the package DB.
  1306.  
  1307.       DDDDeeeebbbbuuuuggggggggeeeerrrr IIIInnnntttteeeerrrrnnnnaaaallllssss
  1308.  
  1309.       At the start,    the debugger reads your    rc file    (./._p_e_r_l_d_b or
  1310.       ~/._p_e_r_l_d_b under Unix), which can set important options.
  1311.       This file may    define a subroutine &afterinit to be executed
  1312.       after    the debugger is    initialized.
  1313.  
  1314.  
  1315.  
  1316.  
  1317.      Page 20                        (printed 10/23/98)
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1325.  
  1326.  
  1327.  
  1328.       After    the rc file is read, the debugger reads    environment
  1329.       variable PERLDB_OPTS and parses it as    a rest of O ...    line
  1330.       in debugger prompt.
  1331.  
  1332.       It also maintains magical internal variables,    such as
  1333.       @DB::dbline, %DB::dbline, which are aliases for
  1334.       @{"::_<current_file"}    %{"::_<current_file"}.    Here
  1335.       current_file is the currently    selected (with the debugger's
  1336.       f command, or    by flow    of execution) file.
  1337.  
  1338.       Some functions are provided to simplify customization.  See
  1339.       the section on _D_e_b_u_g_g_e_r _C_u_s_t_o_m_i_z_a_t_i_o_n    for description    of
  1340.       DB::parse_options(string).  The function
  1341.       DB::dump_trace(skip[,    count])    skips the specified number of
  1342.       frames, and returns a    list containing    info about the caller
  1343.       frames (all if count is missing).  Each entry    is a hash with
  1344.       keys context ($ or @), sub (subroutine name, or info about
  1345.       eval), args (undef or    a reference to an array), file,    and
  1346.       line.
  1347.  
  1348.       The function DB::print_trace(FH, skip[, count[, short]])
  1349.       prints formatted info    about caller frames.  The last two
  1350.       functions may    be convenient as arguments to <, << commands.
  1351.  
  1352.       OOOOtttthhhheeeerrrr    rrrreeeessssoooouuuurrrrcccceeeessss
  1353.  
  1354.       You did try the ----wwww switch, didn't you?
  1355.  
  1356.       BBBBUUUUGGGGSSSS
  1357.  
  1358.       You cannot get the stack frame information or    otherwise
  1359.       debug    functions that were not    compiled by Perl, such as C or
  1360.       C++ extensions.
  1361.  
  1362.       If you alter your @_ arguments in a subroutine (such as with
  1363.       sssshhhhiiiifffftttt    or ppppoooopppp,    the stack backtrace will not show the original
  1364.       values.
  1365.  
  1366.      DDDDeeeebbbbuuuuggggggggiiiinnnngggg PPPPeeeerrrrllll mmmmeeeemmmmoooorrrryyyy uuuussssaaaaggggeeee
  1367.       Perl is _v_e_r_y frivolous with memory.  There is    a saying that
  1368.       to estimate memory usage of Perl, assume a reasonable
  1369.       algorithm of allocation, and multiply    your estimages by 10.
  1370.       This is not absolutely true, but may give you    a good grasp
  1371.       of what happens.
  1372.  
  1373.       Say, an integer cannot take less than    20 bytes of memory, a
  1374.       float    cannot take less than 24 bytes,    a string cannot    take
  1375.       less than 32 bytes (all these    examples assume    32-bit
  1376.       architectures, the result are    much worse on 64-bit
  1377.       architectures).  If a    variable is accessed in    two of three
  1378.       different ways (which    require    an integer, a float, or    a
  1379.       string), the memory footprint    may increase by    another    20
  1380.  
  1381.  
  1382.  
  1383.      Page 21                        (printed 10/23/98)
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1391.  
  1392.  
  1393.  
  1394.       bytes.  A sloppy _m_a_l_l_o_c() implementation will    make these
  1395.       numbers yet more.
  1396.  
  1397.       On the opposite end of the scale, a declaration like
  1398.  
  1399.         sub    foo;
  1400.  
  1401.       may take (on some versions of    perl) up to 500    bytes of
  1402.       memory.
  1403.  
  1404.       Off-the-cuff anecdotal estimates of a    code bloat give    a
  1405.       factor around    8.  This means that the    compiled form of
  1406.       reasonable (commented    indented etc.)    code will take
  1407.       approximately    8 times    more than the disk space the code
  1408.       takes.
  1409.  
  1410.       There    are two    Perl-specific ways to analyze the memory
  1411.       usage:  $ENV{PERL_DEBUG_MSTATS} and ----DDDDLLLL switch.  First one
  1412.       is available only if perl is compiled    with Perl's _m_a_l_l_o_c(),
  1413.       the second one only if Perl compiled with -DDEBUGGING    (as
  1414.       with giving -D optimise=-g option to _C_o_n_f_i_g_u_r_e).
  1415.  
  1416.       UUUUssssiiiinnnngggg    $$$$EEEENNNNVVVV{{{{PPPPEEEERRRRLLLL____DDDDEEEEBBBBUUUUGGGG____MMMMSSSSTTTTAAAATTTTSSSS}}}}
  1417.  
  1418.       If your perl is using    Perl's _m_a_l_l_o_c(), and compiled with
  1419.       correct switches (this is the    default), then it will print
  1420.       memory usage statistics after    compiling your code (if
  1421.       $ENV{PERL_DEBUG_MSTATS} > 1),    and before termination of the
  1422.       script (if $ENV{PERL_DEBUG_MSTATS} >=    1).  The report    format
  1423.       is similar to    one in the following example:
  1424.  
  1425.         env    PERL_DEBUG_MSTATS=2 perl -e "require Carp"
  1426.         Memory allocation statistics after compilation: (buckets 4(4)..8188(8192)
  1427.            14216 free:   130   117      28     7     9   0   2     2     1 0 0
  1428.               437     61    36     0        5
  1429.            60924 used:   125   137     161    55     7   8   6    16     2 0 1
  1430.                74    109   304    84       20
  1431.         Total sbrk(): 77824/21:119.    Odd ends: pad+heads+chain+tail:    0+636+0+2048.
  1432.         Memory allocation statistics after execution:   (buckets 4(4)..8188(8192)
  1433.            30888 free:   245    78      85    13     6   2   1     3     2 0 1
  1434.               315    162    39    42       11
  1435.           175816 used:   265   176    1112   111    26  22  11    27     2 1 1
  1436.               196    178  1066   798       39
  1437.         Total sbrk(): 215040/47:145. Odd ends: pad+heads+chain+tail: 0+2192+0+6144.
  1438.  
  1439.       It is    possible to ask    for such a statistic at    arbitrary
  1440.       moment by usind _D_e_v_e_l::_P_e_e_k::_m_s_t_a_t_s()    (module    Devel::Peek is
  1441.       available on CPAN).
  1442.  
  1443.       Here is the explanation of different parts of    the format:
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.      Page 22                        (printed 10/23/98)
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1457.  
  1458.  
  1459.  
  1460.       buckets SMALLEST(APPROX)..GREATEST(APPROX)
  1461.            Perl's _m_a_l_l_o_c() uses bucketed allocations.  Every
  1462.            request is rounded up to    the closest bucket size
  1463.            available, and a    bucket of these    size is    taken from the
  1464.            pool of the buckets of this size.
  1465.  
  1466.            The above line describes    limits of buckets currently in
  1467.            use.  Each bucket has two sizes:    memory footprint, and
  1468.            the maximal size    of user    data which may be put into
  1469.            this bucket.  Say, in the above example the smallest
  1470.            bucket is both sizes 4.    The biggest bucket has usable
  1471.            size 8188, and the memory footprint 8192.
  1472.  
  1473.            With debugging Perl some    buckets    may have negative
  1474.            usable size.  This means    that these buckets cannot (and
  1475.            will not) be used.  For greater buckets the memory
  1476.            footprint may be    one page greater than a    power of 2.
  1477.            In such a case the corresponding    power of two is
  1478.            printed instead in the APPROX field above.
  1479.  
  1480.       Free/Used
  1481.            The following 1 or 2 rows of numbers correspond to the
  1482.            number of buckets of each size between SMALLEST and
  1483.            GREATEST.  In the first row the sizes (memory
  1484.            footprints) of buckets are powers of two    (or possibly
  1485.            one page    greater).  In the second row (if present) the
  1486.            memory footprints of the    buckets    are between memory
  1487.            footprints of two buckets "above".
  1488.  
  1489.            Say, with the above example the memory footprints are
  1490.            (with current algorith)
  1491.  
  1492.             free:    8       16     32    64    128  256 512 1024 2048 4096 8192
  1493.               4    12    24    48      80
  1494.  
  1495.            With non-DEBUGGING perl the buckets starting from
  1496.            128-long    ones have 4-byte overhead, thus    8192-long
  1497.            bucket may take up to 8188-byte-long allocations.
  1498.  
  1499.       Total    sbrk():    SBRKed/SBRKs:CONTINUOUS
  1500.            The first two fields give the total amount of memory
  1501.            perl _s_b_r_k()ed, and number of _s_b_r_k()s used.  The third
  1502.            number is what perl thinks about    continuity of returned
  1503.            chunks.    As far as this number is positive, _m_a_l_l_o_c()
  1504.            will assume that    it is probable that _s_b_r_k() will
  1505.            provide continuous memory.
  1506.  
  1507.            The amounts _s_b_r_k()ed by external    libraries is not
  1508.            counted.
  1509.  
  1510.       pad: 0
  1511.            The amount of _s_b_r_k()ed memory needed to keep buckets
  1512.  
  1513.  
  1514.  
  1515.      Page 23                        (printed 10/23/98)
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1523.  
  1524.  
  1525.  
  1526.            aligned.
  1527.  
  1528.       heads: 2192
  1529.            While memory overhead of    bigger buckets is kept inside
  1530.            the bucket, for smaller buckets it is kept in separate
  1531.            areas.  This field gives    the total size of these    areas.
  1532.  
  1533.       chain: 0
  1534.            _m_a_l_l_o_c()    may want to subdivide a    bigger bucket into
  1535.            smaller buckets.     If only a part    of the deceased-bucket
  1536.            is left non-subdivided, the rest    is kept    as an element
  1537.            of a linked list.  This field gives the total size of
  1538.            these chunks.
  1539.  
  1540.       tail:    6144
  1541.            To minimize amount of _s_b_r_k()s _m_a_l_l_o_c() asks for more
  1542.            memory.    This field gives the size of the yet-unused
  1543.            part, which is _s_b_r_k()ed,    but never touched.
  1544.  
  1545.       EEEExxxxaaaammmmpppplllleeee ooooffff uuuussssiiiinnnngggg ----DDDDLLLL switch
  1546.  
  1547.       Below    we show    how to analyse memory usage by
  1548.  
  1549.         do 'lib/auto/POSIX/autosplit.ix';
  1550.  
  1551.       The file in question contains    a header and 146 lines similar
  1552.       to
  1553.  
  1554.         sub    getcwd ;
  1555.  
  1556.       NNNNooootttteeee::::    _t_h_e _d_i_s_c_u_s_s_i_o_n _b_e_l_o_w _s_u_p_p_o_s_e_s _3_2-_b_i_t _a_r_c_h_i_t_e_c_t_u_r_e.  _I_n
  1557.       _t_h_e _n_e_w_e_r _v_e_r_s_i_o_n_s _o_f    _p_e_r_l _t_h_e _m_e_m_o_r_y    _u_s_a_g_e _o_f _t_h_e
  1558.       _c_o_n_s_t_r_u_c_t_s _d_i_s_c_u_s_s_e_d _h_e_r_e _i_s _m_u_c_h _i_m_p_r_o_v_e_d, _b_u_t _t_h_e _s_t_o_r_y
  1559.       _d_i_s_c_u_s_s_e_d _b_e_l_o_w _i_s _a _r_e_a_l-_l_i_f_e _s_t_o_r_y.     _T_h_i_s _s_t_o_r_y _i_s _v_e_r_y
  1560.       _t_e_r_s_e, _a_n_d _a_s_s_u_m_e_s _m_o_r_e _t_h_a_n _c_u_r_s_o_r_y _k_n_o_w_l_e_d_g_e _o_f _P_e_r_l
  1561.       _i_n_t_e_r_n_a_l_s.
  1562.  
  1563.       Here is the itemized list of Perl allocations    performed
  1564.       during parsing of this file:
  1565.  
  1566.        !!! "after" at test.pl line 3.
  1567.           Id  subtot   4   8  12  16  20  24  28  32  36  40  48  56  64  72  80 80+
  1568.         0 02   13752   .   .   .   . 294   .   .   .   .   .   .   .   .   .   .   4
  1569.         0 54    5545   .   .   8 124  16   .   .   .   1   1   .   .   .   .   .   3
  1570.         5 05      32   .   .   .   .   .   .   .   1   .   .   .   .   .   .   .   .
  1571.         6 02    7152   .   .   .   .   .   .   .   .   .   . 149   .   .   .   .   .
  1572.         7 02    3600   .   .   .   .   . 150   .   .   .   .   .   .   .   .   .   .
  1573.         7 03      64   .  -1   .   1   .   .   2   .   .   .   .   .   .   .   .   .
  1574.         7 04    7056   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   7
  1575.         7 17   38404   .   .   .   .   .   .   .   1   .   . 442 149   .   . 147   .
  1576.         9 03    2078  17 249  32   .   .   .   .   2   .   .   .   .   .   .   .   .
  1577.  
  1578.  
  1579.  
  1580.  
  1581.      Page 24                        (printed 10/23/98)
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1589.  
  1590.  
  1591.  
  1592.       To see this list insert two warn('!...') statements around
  1593.       the call:
  1594.  
  1595.         warn('!');
  1596.         do 'lib/auto/POSIX/autosplit.ix';
  1597.         warn('!!! "after"');
  1598.  
  1599.       and run it with ----DDDDLLLL option.  The first _w_a_r_n()    will print
  1600.       memory allocation info before    the parsing of the file, and
  1601.       will memorize    the statistics at this point (we ignore    what
  1602.       it prints). The second _w_a_r_n()    will print increments w.r.t.
  1603.       this memorized statistics.  This is the above    printout.
  1604.  
  1605.       Different _I_ds    on the left correspond to different subsystems
  1606.       of perl interpreter, they are    just first argument given to
  1607.       perl memory allocation API _N_e_w().  To    find what 9 03 means
  1608.       grep the perl    source for 903.     You will see that it is
  1609.       _u_t_i_l._c, function _s_a_v_e_p_v_n().  This function is    used to    store
  1610.       a copy of existing chunk of memory.  Using C debugger, one
  1611.       can see that it is called either directly from _g_v__i_n_i_t(), or
  1612.       via _s_v__m_a_g_i_c(), and _g_v__i_n_i_t()    is called from _g_v__f_e_t_c_h_p_v() -
  1613.       which    is called from _n_e_w_S_U_B().
  1614.  
  1615.       NNNNooootttteeee::::    to reach this place in debugger    and skip all the calls
  1616.       to savepvn during the    compilation of the main    script,    set a
  1617.       C breakpoint in _P_e_r_l__w_a_r_n(), continue    this point is reached,
  1618.       _t_h_e_n set breakpoint in _P_e_r_l__s_a_v_e_p_v_n().  Note that you    may
  1619.       need to skip a handful of _P_e_r_l__s_a_v_e_p_v_n() which do not
  1620.       correspond to    mass production    of CVs (there are more 903
  1621.       allocations than 146 similar lines of
  1622.       _l_i_b/_a_u_t_o/_P_O_S_I_X/_a_u_t_o_s_p_l_i_t._i_x).     Note also that    Perl_ prefixes
  1623.       are added by macroization code in perl header    files to avoid
  1624.       conflicts with external libraries.
  1625.  
  1626.       Anyway, we see that 903 ids correspond to creation of    globs,
  1627.       twice    per glob - for glob name, and glob stringification
  1628.       magic.
  1629.  
  1630.       Here are explanations    for other _I_ds above:
  1631.  
  1632.       717  is for creation of bigger XPV* structures.  In the
  1633.            above case it creates 3 AV per subroutine, one for a
  1634.            list of lexical variable    names, one for a scratchpad
  1635.            (which contains lexical variables and targets), and one
  1636.            for the array of    scratchpads needed for recursion.
  1637.  
  1638.            It also creates a GV and    a CV per subroutine (all
  1639.            called from _s_t_a_r_t__s_u_b_p_a_r_s_e()).
  1640.  
  1641.       002  Creates C array corresponding to    the AV of scratchpads,
  1642.            and the scratchpad itself (the first fake entry of this
  1643.            scratchpad is created though the    subroutine itself is
  1644.  
  1645.  
  1646.  
  1647.      Page 25                        (printed 10/23/98)
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1655.  
  1656.  
  1657.  
  1658.            not defined yet).
  1659.  
  1660.            It also creates C arrays    to keep    data for the stash
  1661.            (this is    one HV,    but it grows, thus there are 4 big
  1662.            allocations: the    big chunks are not freeed, but are
  1663.            kept as additional arenas for SV    allocations).
  1664.  
  1665.       054  creates a HEK for the name of the glob for the
  1666.            subroutine (this    name is    a key in a _s_t_a_s_h).
  1667.  
  1668.            Big allocations with this _I_d correspond to allocations
  1669.            of new arenas to    keep HE.
  1670.  
  1671.       602  creates a GP for    the glob for the subroutine.
  1672.  
  1673.       702  creates the MAGIC for the glob for the subroutine.
  1674.  
  1675.       704  creates _a_r_e_n_a_s which keep SVs.
  1676.  
  1677.       ----DDDDLLLL details
  1678.  
  1679.       If Perl is run with ----DDDDLLLL option, then _w_a_r_n()s which start
  1680.       with `!'  behave specially.  They print a list of _c_a_t_e_g_o_r_i_e_s
  1681.       of memory allocations, and statistics    of allocations of
  1682.       different sizes for these categories.
  1683.  
  1684.       If _w_a_r_n() string starts with
  1685.  
  1686.       !!!  print changed categories    only, print the    differences in
  1687.            counts of allocations;
  1688.  
  1689.       !!   print grown categories only; print the absolute values
  1690.            of counts, and totals;
  1691.  
  1692.       !    print nonempty categories, print    the absolute values of
  1693.            counts and totals.
  1694.  
  1695.       LLLLiiiimmmmiiiittttaaaattttiiiioooonnnnssss ooooffff ----DDDDLLLL statistic
  1696.  
  1697.       If an    extension or an    external library does not use Perl API
  1698.       to allocate memory, these allocations    are not    counted.
  1699.  
  1700.      DDDDeeeebbbbuuuuggggggggiiiinnnngggg rrrreeeegggguuuullllaaaarrrr eeeexxxxpppprrrreeeessssssssiiiioooonnnnssss
  1701.       There    are two    ways to    enable debugging output    for regular
  1702.       expressions.
  1703.  
  1704.       If your perl is compiled with    -DDEBUGGING, you may use the
  1705.       ----DDDDrrrr flag on the command line.
  1706.  
  1707.       Otherwise, one can use re 'debug', which has effects both at
  1708.       compile time,    and at run time    (and is    _n_o_t lexically scoped).
  1709.  
  1710.  
  1711.  
  1712.  
  1713.      Page 26                        (printed 10/23/98)
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1721.  
  1722.  
  1723.  
  1724.       CCCCoooommmmppppiiiilllleeee----ttttiiiimmmmeeee oooouuuuttttppppuuuutttt
  1725.  
  1726.       The debugging    output for the compile time looks like this:
  1727.  
  1728.         compiling RE `[bc]d(ef*g)+h[ij]k$'
  1729.         size 43 first at 1
  1730.            1: ANYOF(11)
  1731.           11: EXACT    <d>(13)
  1732.           13: CURLYX {1,32767}(27)
  1733.           15:   OPEN1(17)
  1734.           17:     EXACT <e>(19)
  1735.           19:     STAR(22)
  1736.           20:    EXACT <f>(0)
  1737.           22:     EXACT <g>(24)
  1738.           24:   CLOSE1(26)
  1739.           26:   WHILEM(0)
  1740.           27: NOTHING(28)
  1741.           28: EXACT    <h>(30)
  1742.           30: ANYOF(40)
  1743.           40: EXACT    <k>(42)
  1744.           42: EOL(43)
  1745.           43: END(0)
  1746.         anchored `de' at 1 floating    `gh' at    3..2147483647 (checking    floating)
  1747.                           stclass `ANYOF' minlen 7
  1748.  
  1749.       The first line shows the pre-compiled    form of    the regexp,
  1750.       and the second shows the size    of the compiled    form (in
  1751.       arbitrary units, usually 4-byte words) and the label _i_d of
  1752.       the first node which does a match.
  1753.  
  1754.       The last line    (split into two    lines in the above) contains
  1755.       the optimizer    info.  In the example shown, the optimizer
  1756.       found    that the match should contain a    substring de at    the
  1757.       offset 1, and    substring gh at    some offset between 3 and
  1758.       infinity.  Moreover, when checking for these substrings (to
  1759.       abandon impossible matches quickly) it will check for    the
  1760.       substring gh before checking for the substring de.  The
  1761.       optimizer may    also use the knowledge that the    match starts
  1762.       (at the first    _i_d) with a character class, and    the match
  1763.       cannot be shorter than 7 chars.
  1764.  
  1765.       The fields of    interest which may appear in the last line are
  1766.  
  1767.       anchored _S_T_R_I_N_G at _P_O_S
  1768.  
  1769.       floating _S_T_R_I_N_G at _P_O_S_1.._P_O_S_2
  1770.            see above;
  1771.  
  1772.       matching floating/anchored
  1773.            which substring to check    first;
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.      Page 27                        (printed 10/23/98)
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1787.  
  1788.  
  1789.  
  1790.       minlen
  1791.            the minimal length of the match;
  1792.  
  1793.       stclass _T_Y_P_E
  1794.            The type    of the first matching node.
  1795.  
  1796.       noscan
  1797.            which advises to    not scan for the found substrings;
  1798.  
  1799.       isall
  1800.            which says that the optimizer info is in    fact all that
  1801.            the regular expression contains (thus one does not need
  1802.            to enter    the RE engine at all);
  1803.  
  1804.       GPOS if the pattern contains \G;
  1805.  
  1806.       plus if the pattern starts with a repeated char (as in x+y);
  1807.  
  1808.       implicit
  1809.            if the pattern starts with .*;
  1810.  
  1811.       with eval
  1812.            if the pattern contain eval-groups (see the section on
  1813.            (?{ _c_o_d_e    }) in the _p_e_r_l_r_e manpage);
  1814.  
  1815.       anchored(TYPE)
  1816.            if the pattern may match    only at    a handful of places
  1817.            (with TYPE being    BOL, MBOL, or GPOS, see    the table
  1818.            below).
  1819.  
  1820.       If a substring is known to match at end-of-line only,    it may
  1821.       be followed by $, as in floating `k'$.
  1822.  
  1823.       The optimizer-specific info is used to avoid entering    (a
  1824.       slow)    RE engine on strings which will    definitely not match.
  1825.       If isall flag    is set,    a call to the RE engine    may be avoided
  1826.       even when optimizer found an appropriate place for the
  1827.       match.
  1828.  
  1829.       The rest of the output contains the list of _n_o_d_e_s of the
  1830.       compiled form    of the RE.  Each line has format
  1831.  
  1832.          _i_d: _T_Y_P_E _O_P_T_I_O_N_A_L-_I_N_F_O (_n_e_x_t-_i_d)
  1833.  
  1834.       TTTTyyyyppppeeeessss    ooooffff nnnnooooddddeeeessss
  1835.  
  1836.       Here is the list of possible types with short    descriptions:
  1837.  
  1838.           #    TYPE arg-description [num-args]    [longjump-len] DESCRIPTION
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.      Page 28                        (printed 10/23/98)
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1853.  
  1854.  
  1855.  
  1856.           #    Exit points
  1857.           END      no      End of program.
  1858.           SUCCEED      no      Return from a    subroutine, basically.
  1859.  
  1860.           #    Anchors:
  1861.           BOL      no      Match    "" at beginning    of line.
  1862.           MBOL      no      Same,    assuming multiline.
  1863.           SBOL      no      Same,    assuming singleline.
  1864.           EOS      no      Match    "" at end of string.
  1865.           EOL      no      Match    "" at end of line.
  1866.           MEOL      no      Same,    assuming multiline.
  1867.           SEOL      no      Same,    assuming singleline.
  1868.           BOUND      no      Match    "" at any word boundary
  1869.           BOUNDL      no      Match    "" at any word boundary
  1870.           NBOUND      no      Match    "" at any word non-boundary
  1871.           NBOUNDL      no      Match    "" at any word non-boundary
  1872.           GPOS      no      Matches where    last m//g left off.
  1873.  
  1874.           #    [Special] alternatives
  1875.           ANY      no      Match    any one    character (except newline).
  1876.           SANY      no      Match    any one    character.
  1877.           ANYOF      sv      Match    character in (or not in) this class.
  1878.           ALNUM      no      Match    any alphanumeric character
  1879.           ALNUML      no      Match    any alphanumeric char in locale
  1880.           NALNUM      no      Match    any non-alphanumeric character
  1881.           NALNUML      no      Match    any non-alphanumeric char in locale
  1882.           SPACE      no      Match    any whitespace character
  1883.           SPACEL      no      Match    any whitespace char in locale
  1884.           NSPACE      no      Match    any non-whitespace character
  1885.           NSPACEL      no      Match    any non-whitespace char    in locale
  1886.           DIGIT      no      Match    any numeric character
  1887.           NDIGIT      no      Match    any non-numeric    character
  1888.  
  1889.           #    BRANCH      The set of branches constituting a single choice are hooked
  1890.           #          together with    their "next" pointers, since precedence    prevents
  1891.           #          anything being concatenated to any individual    branch.     The
  1892.           #          "next" pointer of the    last BRANCH in a choice    points to the
  1893.           #          thing    following the whole choice.  This is also where    the
  1894.           #          final    "next" pointer of each individual branch points; each
  1895.           #          branch starts    with the operand node of a BRANCH node.
  1896.           #
  1897.           BRANCH      node      Match    this alternative, or the next...
  1898.  
  1899.           #    BACK      Normal "next"    pointers all implicitly    point forward; BACK
  1900.           #          exists to make loop structures possible.
  1901.           #    not used
  1902.           BACK      no      Match    "", "next" ptr points backward.
  1903.  
  1904.           #    Literals
  1905.           EXACT      sv      Match    this string (preceded by length).
  1906.           EXACTF      sv      Match    this string, folded (prec. by length).
  1907.           EXACTFL      sv      Match    this string, folded in locale (w/len).
  1908.  
  1909.  
  1910.  
  1911.      Page 29                        (printed 10/23/98)
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1919.  
  1920.  
  1921.  
  1922.           #    Do nothing
  1923.           NOTHING      no      Match    empty string.
  1924.           #    A variant of above which delimits a group, thus    stops optimizations
  1925.           TAIL      no      Match    empty string. Can jump here from outside.
  1926.  
  1927.           #    STAR,PLUS '?', and complex '*' and '+',    are implemented    as circular
  1928.           #          BRANCH structures using BACK.     Simple    cases (one character
  1929.           #          per match) are implemented with STAR and PLUS    for speed
  1930.           #          and to minimize recursive plunges.
  1931.           #
  1932.           STAR      node      Match    this (simple) thing 0 or more times.
  1933.           PLUS      node      Match    this (simple) thing 1 or more times.
  1934.  
  1935.           CURLY      sv 2      Match    this simple thing {n,m}    times.
  1936.           CURLYN      no 2      Match    next-after-this    simple thing
  1937.           #              {n,m}    times, set parenths.
  1938.           CURLYM      no 2      Match    this medium-complex thing {n,m}    times.
  1939.           CURLYX      sv 2      Match    this complex thing {n,m} times.
  1940.  
  1941.           #    This terminator    creates    a loop structure for CURLYX
  1942.           WHILEM      no      Do curly processing and see if rest matches.
  1943.  
  1944.           #    OPEN,CLOSE,GROUPP ...are numbered at compile time.
  1945.           OPEN      num 1      Mark this point in input as start of #n.
  1946.           CLOSE      num 1      Analogous to OPEN.
  1947.  
  1948.           REF      num 1      Match    some already matched string
  1949.           REFF      num 1      Match    already    matched    string,    folded
  1950.           REFFL      num 1      Match    already    matched    string,    folded in loc.
  1951.  
  1952.           #    grouping assertions
  1953.           IFMATCH      off 1    2 Succeeds if the following matches.
  1954.           UNLESSM      off 1    2 Fails    if the following matches.
  1955.           SUSPEND      off 1    1 "Independent"    sub-RE.
  1956.           IFTHEN      off 1    1 Switch, should be preceeded by switcher .
  1957.           GROUPP      num 1      Whether the group matched.
  1958.  
  1959.           #    Support    for long RE
  1960.           LONGJMP      off 1    1 Jump far away.
  1961.           BRANCHJ      off 1    1 BRANCH with long offset.
  1962.  
  1963.           #    The heavy worker
  1964.           EVAL      evl 1      Execute some Perl code.
  1965.  
  1966.           #    Modifiers
  1967.           MINMOD      no      Next operator    is not greedy.
  1968.           LOGICAL      no      Next opcode should set the flag only.
  1969.  
  1970.           #    This is    not used yet
  1971.           RENUM      off 1    1 Group    with independently numbered parens.
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.      Page 30                        (printed 10/23/98)
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  1985.  
  1986.  
  1987.  
  1988.           #    This is    not really a node, but an optimized away piece of a "long" node.
  1989.           #    To simplify debugging output, we mark it as if it were a node
  1990.           OPTIMIZED      off      Placeholder for dump.
  1991.  
  1992.  
  1993.       RRRRuuuunnnn----ttttiiiimmmmeeee oooouuuuttttppppuuuutttt
  1994.  
  1995.       First    of all,    when doing a match, one    may get    no run-time
  1996.       output even if debugging is enabled.    this means that    the RE
  1997.       engine was never entered, all    of the job was done by the
  1998.       optimizer.
  1999.  
  2000.       If RE    engine was entered, the    output may look    like this:
  2001.  
  2002.         Matching `[bc]d(ef*g)+h[ij]k$' against `abcdefg__gh__'
  2003.           Setting an EVAL scope, savestack=3
  2004.            2 <ab> <cdefg__gh_>    |     1: ANYOF
  2005.            3 <abc> <defg__gh_>    |    11: EXACT <d>
  2006.            4 <abcd>    <efg__gh_>    |    13: CURLYX {1,32767}
  2007.            4 <abcd>    <efg__gh_>    |    26:   WHILEM
  2008.                       0 out    of 1..32767  cc=effff31c
  2009.            4 <abcd>    <efg__gh_>    |    15:    OPEN1
  2010.            4 <abcd>    <efg__gh_>    |    17:    EXACT <e>
  2011.            5 <abcde> <fg__gh_>    |    19:    STAR
  2012.                        EXACT <f> can match 1 times out of 32767...
  2013.           Setting an EVAL scope, savestack=3
  2014.            6 <bcdef> <g__gh__>    |    22:      EXACT    <g>
  2015.            7 <bcdefg> <__gh__>    |    24:      CLOSE1
  2016.            7 <bcdefg> <__gh__>    |    26:      WHILEM
  2017.                           1    out of 1..32767     cc=effff31c
  2018.           Setting an EVAL scope, savestack=12
  2019.            7 <bcdefg> <__gh__>    |    15:        OPEN1
  2020.            7 <bcdefg> <__gh__>    |    17:        EXACT <e>
  2021.          restoring \1 to 4(4)..7
  2022.                           failed, try continuation...
  2023.            7 <bcdefg> <__gh__>    |    27:        NOTHING
  2024.            7 <bcdefg> <__gh__>    |    28:        EXACT <h>
  2025.                           failed...
  2026.                       failed...
  2027.  
  2028.       The most significant information in the output is about the
  2029.       particular _n_o_d_e of the compiled RE which is currently    being
  2030.       tested against the target string.  The format    of these lines
  2031.       is
  2032.  
  2033.           _S_T_R_I_N_G-_O_F_F_S_E_T <_P_R_E-_S_T_R_I_N_G> <_P_O_S_T-_S_T_R_I_N_G>     |_I_D:  _T_Y_P_E
  2034.  
  2035.       The _T_Y_P_E info    is indented with respect to the    backtracking
  2036.       level.  Other    incidental information appears interspersed
  2037.       within.
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.      Page 31                        (printed 10/23/98)
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))    22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))      PPPPEEEERRRRLLLLDDDDEEEEBBBBUUUUGGGG((((1111))))
  2051.  
  2052.  
  2053.  
  2054.  
  2055.  
  2056.  
  2057.  
  2058.  
  2059.  
  2060.  
  2061.  
  2062.  
  2063.  
  2064.  
  2065.  
  2066.  
  2067.  
  2068.  
  2069.  
  2070.  
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.  
  2078.  
  2079.  
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.      Page 32                        (printed 10/23/98)
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.